using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.ActiveRecord;
using NHibernate.Expression;

/// <summary>
/// Summary description for Admin
/// </summary>
/// 
[ActiveRecord("Admin")]
public class Admin : ActiveRecordBase<Admin>
{
    public static  MatchMode Exact = MatchMode.Exact;
    public static   MatchMode Anywhere = MatchMode.Anywhere;
    public static  MatchMode End = MatchMode.End;
    public static  MatchMode Start = MatchMode.Start;   

    private int iD;  

    [PrimaryKey(PrimaryKeyType.Identity)]
    public int ID
    {
        get { return iD; }
        set { iD = value; }
    }

    private int siteID;

    [Property]
    public int SiteID
    {
        get { return siteID; }
        set { siteID = value; }
    }

    private String userName;

    [Property(Unique=true)]
    public String UserName
    {
        get { return userName; }
        set { userName = value; }
    }

    private String password;

    [Property]
    public String Password
    {
        get { return password; }
        set { password = value; }
    }

    private String email;
    [Property]
    public String Email
    {
        get { return email; }
        set { email = value; }
    }

    private String firstName;
    [Property]
    public String FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }

    private String lastName;
    [Property]
    public String LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }

    private bool activeFlag;
    [Property]
    public bool ActiveFlag
    {
        get { return activeFlag; }
        set { activeFlag = value; }
    }

    private DateTime createdDate;
    [Property]
    public DateTime CreatedDate
    {
        get { return createdDate; }
        set { createdDate = value; }
    }

    private DateTime updatedDate;
    [Property]
    public DateTime UpdatedDate
    {
        get { return updatedDate; }
        set { updatedDate = value; }
    }

    private int createdUserID;

    [Property]
    public int CreatedUserID
    {
        get { return createdUserID; }
        set { createdUserID = value; }
    }

    private int updatedUserID;


    [Property]
    public int UpdatedUserID
    {
        get { return updatedUserID; }
        set { updatedUserID = value; }
    }

	public Admin()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public Admin(String userName, String password, String email, String firstName, String lastName, bool activeFlag, String createdBy)
    {
        //this.userName = userName;
        //this.password = password;
        //this.email = email;
        //this.firstName = firstName;
        //this.lastName = lastName;
        //this.activeFlag = activeFlag;
        //this.createdDate = DateTime.Now;
        //this.updatedDate = DateTime.Now;
        //this.createdBy = createdBy;
        //this.updatedBy = createdBy;        
    }

    public static void delete_admin(int adminid)
    {
        Admin admin = get_admin(adminid);
        admin.Delete();
    }

    public static void update_admin(int adminID, String userName, String password, String email, String firstName, String lastName, bool activeFlag, String updatedBy)
    {
        //Admin admin = new Admin();
        //admin = get_admin(adminID);
        //admin.userName = userName;
        //admin.password = password;
        //admin.email = email;
        //admin.firstName = firstName;
        //admin.lastName = lastName;
        //admin.activeFlag = activeFlag;
        //admin.UpdatedBy = updatedBy;
        //admin.updatedDate = DateTime.Now;
        //admin.Update();
    }

    public static void update_admin(int adminID,bool activeFlag,String updatedBy)
    {
        //Admin admin = new Admin();
        //admin = get_admin(adminID);        
        //admin.activeFlag = activeFlag;
        //admin.UpdatedBy = updatedBy;
        //admin.updatedDate = DateTime.Now;
        //admin.Update();
    }

    public static void create_admin(String userName, String password, String email, String firstName, String lastName,  bool activeFlag, String createdBy)
    {
        //Admin admin = new Admin(userName, password, email, firstName, lastName, activeFlag, createdBy);
        //admin.Create();
        
    }

    public static Admin get_admin(String username)
    {
        //try
        //{
        //    Admin[] admins = FindAllByProperty("UserName", adminname);
        //    return admins[0];
        //}
        //catch (Exception ex)
        //{
        //    return null;
        //}

        return FindOne(Expression.Eq("UserName", username));
    }

    public static Admin get_admin(int adminid)
    {
        return FindByPrimaryKey(adminid);
    }

    public static Admin[] get_all_admin()
    {
        return FindAll();
    }

    public static int count_all_admin()
    {
        return Count();
    }

    public static Admin[] search_admin(String propertyName,String textSearch,MatchMode mode)
    {
        DetachedCriteria criteria = DetachedCriteria.For<Admin>();
        criteria.Add(Expression.InsensitiveLike(propertyName, textSearch, mode));
        return FindAll(criteria, Admin.Asc("ID"));
    }

    public static Admin[] get_admins_and_sort(String propertyName, String order)
    {
        DetachedCriteria avgWeight = DetachedCriteria.For<Admin>();
        if (order == "ASC")
            return FindAll(avgWeight, Asc(propertyName));
        return FindAll(avgWeight, Desc(propertyName));
    }
}
